/*

*/
#pragma once 
#include <iostream>
#include <functional>
#include <thread>
#include <string>
#include "Thread/TaskQueue.h"
using namespace toolkit;
using namespace std;
class taskManager
{

public:
    taskManager() = default;
    virtual ~taskManager(); 
    static taskManager &Instance();
    void stopThread(bool drop_task);
    

public:
    void startThread(const std::string &name);
    bool pushMsg(std::function<void()> task);
    bool isEnabled() const;

private:
    void onThreadRun(const std::string &name);

private:
    class ThreadExitException : public std::runtime_error {
    public:
        ThreadExitException() : std::runtime_error("exit") {}
        ~ThreadExitException() = default;
    };

private:
  
    bool _exit = false;
    std::shared_ptr<std::thread> _thread;
    TaskQueue<std::function<void()> > _taskqueue;
};